var table;
var element;
var $;
layui.use(['table','element'],function() {
    table = layui.table;
    element = layui.element;
    $ = layui.jquery;

    //页面刷新
    $("#btn_1").on('click',function(){
        location.reload(true);
    })

    var id=$("#forumId").val();
    var commentid=$("#commentid").val();
   getCourse(id);
    getInformation(commentid);
    function getInformation(id){
        $.ajax({
            url:"/SyteacherSelController/SeCommentCourse",
            type:"post",
            dataType:"json",
            data:{"commentid":id},
            success:function(data){
                $("#p_name").text(data.data.userName);
                $("#span_title").text(data.data.courseName);
                $("#span_user").text(data.data.userName);
                $("#span_fenlei").text(resolvingDate(data.data.createDate));
                $("#span_date").text(data.data.courseInfo);
                $("#span_id").text(data.data.account);
            }
        })
    }

    function getCourse(id){
        $.ajax({
            url:"/SyteacherSelController/SeCourseText",
            type:"post",
            dataType:"json",
            data:{"courseid":id},
            success:function(data){
                $("#text_id").text(data.data.courseIntro);
                $("#img_id").html("<img src='/teacher/upload/"+data.data.url+"' style='width: 250px;height: 150px;'></img>");
                $("#span_border1").text(data.data.collectNum);
                $("#span_border2").text(data.data.look_num);
            }
        })
    }

    /*时间转换*/
    function resolvingDate(date){
        var d = new Date(date);
        var month = (d.getMonth() + 1) < 10 ? '0'+(d.getMonth() + 1) : (d.getMonth() + 1);
        var day = d.getDate()<10 ? '0'+d.getDate() : d.getDate();
        var hours = d.getHours()<10 ? '0'+d.getHours() : d.getHours();
        var min = d.getMinutes()<10 ? '0'+d.getMinutes() : d.getMinutes();
        var sec = d.getSeconds()<10 ? '0'+d.getSeconds() : d.getSeconds();
        times=d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
        return times;
    };

    /*评论信息*/
    seComment(id,3);
    function seComment(id,limit){
        $.ajax({
            url:"/SyteacherSelController/SeCommentlimit",
            type:"post",
            dataType:"json",
            data:{"forumid":id,"limitnum":limit},
            success:function(data){
                var html="";
                for(var a=0;a<data.data.length;a++){
                    html+="<div class='contentdiv'><div class='contentdiv1'><i class='layui-icon' id='i_div'>&#xe612;</i></div><div class='singlediv'><p class='nameclass'>"+data.data[a].userName+"</p><p class='nameclass'>回复网友:"+data.data[a].content+"</p><p class='timeclass'>"+resolvingDate(data.data[a].commentDate)+"</p><div class='btnTwo'><a class='a_class'>隐藏</a><a href='#' class='a_class' )'><span onclick='javascript:delectComment(\""+data.data[a].id+"\")'>删除</span></a></div></div></div>";
                }
                $("#comment_id").html(html);
            }
        })


    }

    $("#btn_2").on("click",function(){
        var name=$("#input_id").val();
        var title=$("#text_div1").val();
        $.ajax({
            url:"/SyteacherSelController/SeBefore",
            type:"post",
            dataType:"json",
            data:{"name":name},
            success:function(data){
                var id=$("#forumId").val();
                inComment(data.data.userId,id,title);
            }
        })
    })
})
    /*删除评论*/
    function delectComment(commentid){
        $.ajax({
            url:"/SyteacherSelController/deComment",
            type:"post",
            dataType:"json",
            data:{"cid":commentid},
            success:function(data){
                location.reload(true);
            }
        })
    }

    function inComment(userid,id,title){
        $.ajax({
            url:"/SyteacherSelController/AddCommentCourse",
            type:"post",
            dataType:"json",
            data:{"userid":userid,"id":id,"title":title},
            success:function(data){
                if(data.data){
                    location.reload(true);
                }
            }
        })
    }

